define(function(require, exports, module) {
    var router = require("router");
    //var app = require("app");
    var controller = {};
    controller.vue = function() {
        controller.vm = new Vue({
            router: router,
            data: function() {
                return {
                     shop_id:0,
                     shop_info:{},
                     listData:[],
                     empty:0,
                    

                };
            },
            el: '#pageCartAll',
            created: function() {
                this.fetchData();
            },
            mounted: function() {
                    
                    

            },

            methods: {
                fetchData: function() {
                    var _this = this;
                    
                    // this.shop_id = this.$route.params.shop_id;
                    this.getcartByUserId();
                },
                 // 购物车
                getcartByUserId: function () {
                  var that = this;
                  app.get("mall/cart/getAllCart", function (res) {
                    if (res.code != 200) {
                      app.alert(res.msg);
                    } else if (res.data) {
                       that.listData = res.data;
                    }
                    if (res.data.count===0){
                      that.setData({"empty":1});
                    }
                  });
                },
                setData:function(arr){
                  for( var i in arr){
                    // console.log(i);
                    // console.log(arr[i]);
                     // this.$set(i,arr[i]); 
                     this[i] = arr[i];
                  }
                },
                //清空购物车
                clearCart: function (shop_id) {
                
                  var that = this;
                  app.confirm({
                     text:'确定删除此购物车？',
                     yes:function(){
                          app.get("mall/cart/clearCart", { shop_id: shop_id }, function (res) {
                          if (res.code != 200) {
                            app.alert(res.msg);
                          } else {
                            //phpkitApp.alert("恭喜,成功清空购物车!");
                            app.alert('恭喜,成功清空购物车!');
                            that.getcartByUserId();
                          }
                         
                        });
                     }
                  });
                  
                },

                 
 
            }

        }).$mount('#app');
    };
    module.exports = controller;
});
